package com.itguigu.servlet;

import com.google.gson.Gson;
import com.itguigu.fruit.pojo.Person;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/h10")
public class Hello10Servlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        BufferedReader reader = req.getReader();
        StringBuilder stringBuilder = new StringBuilder();
        String str = null;
        while ((str = reader.readLine()) != null) {
            stringBuilder.append(str);
        }
        str = stringBuilder.toString();
        Gson gson = new Gson();
        Person person = gson.fromJson(str, Person.class);
        PrintWriter writer = resp.getWriter();
        writer.println(person);
        writer.flush();

//        String name = req.getParameter("uname");
//        name = name.toUpperCase();
//        String address = req.getParameter("address");
//        address = address.toUpperCase();
//        PrintWriter writer = resp.getWriter();
//        writer.println(name+"-"+address);
//        writer.flush();

    }
}
